using System;
using System.Collections.Generic;
using System.Text;
using Barrage;
using Spacedash.Logic;
using Barrage.GUI.Meshes;
using Barrage.Textures;
using SlimDX;

namespace Spacedash.Game.Items
{
    /// <summary>
    /// Cursor of a ship in a minimap
    /// </summary>
    public class GUIMinimapCursor:Item
    {
        Race race;
        Ship ship;

        SimpleRectangle cursor;

        const float CURSOR_SIZE_X = 96;
        const float CURSOR_SIZE_Y = 32;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="race">Race instance</param>
        /// <param name="ship">Ship that this icon is showing on the minimap</param>
        public GUIMinimapCursor(Race race, Ship ship)
        {
            this.race = race;
            this.ship = ship;
            cursor = new SimpleRectangle(TextureManager.Textures["GUI/Minimap_Cursor.png"], new Vector2(CURSOR_SIZE_X, CURSOR_SIZE_Y));
            addMesh(cursor);
        }
        /// <summary>
        /// \internal Updates icon position and color based on ship's position in the race scenario
        /// </summary>
        protected override void DoUpdate()
        {
            float ySize = GUIMinimap.SIZE_Y - 2 * GUIMinimap.MARGIN;
            float div = ship.ScenarioPosition.Y / race.Scenario.RowNumber;
            float rem = div - (float)Math.Floor(div);
            cursor.FirstMaterial.Diffuse = new Color4(ship.Color);
            motion.Translation = new Vector3(motion.Translation.X, (rem - 0.5f) * ySize, 0);
            base.DoUpdate();
        }
    }
}
